﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Globalization;
using System.Resources;

using EHTWebsite.Code;

public partial class Index : System.Web.UI.Page
{
    public Boolean IsVN = true;
    private String languageCode = "vi-VN";
    private Int32 categoryID = -1;
    private Int32 pageIndex = 1;
    private Int32 pageSize = 12;
    private Int32 totalRecord = 0;
    private ResourceManager rm = new ResourceManager("Resources.SiteMap", System.Reflection.Assembly.Load("App_GlobalResources"));

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            languageCode = Session[HangSo.LANGUAGE_CODE].ToString();

            if (languageCode == "en-us")
            {
                IsVN = false;
            }

        }
        catch (Exception ex)
        {
        }

        if (!Page.IsPostBack)
        {
            ThongTinCongTy theThongTinCongTy = ThongTinCongTyProvider.GetThongTinCongTy();

            if (theThongTinCongTy != null)
            {
                if (IsVN == true)
                {
                    this.ltrCompanyName.Text = theThongTinCongTy.TenCongTyVN;
                    this.ltrGioiThieuTomTat.Text = theThongTinCongTy.GioiThieuTomTatVN;
                }
                else
                {
                    this.ltrCompanyName.Text = theThongTinCongTy.TenCongTyOther;
                    this.ltrGioiThieuTomTat.Text = theThongTinCongTy.GioiThieuTomTatOther;
                }
            }

            LoadHinhAnhCongTys();

            //LoadSanPham();
            //LoadTopLastestNews();

            Thread.CurrentThread.CurrentCulture = new CultureInfo(languageCode);
            LoadLanguage(Thread.CurrentThread.CurrentCulture);
        }

    }

    private void LoadHinhAnhCongTys()
    {
        this.rpHinhAnhSanPham.DataSource = HinhAnhCongTyProvider.GetHinhAnhCongTysForFrontEnd(1, 10000, out totalRecord);
        this.rpHinhAnhSanPham.DataBind();

        //this.rpSanPhams.DataSource = SanPhamProvider.GetSanPhamsByFilter(theSanPham, pageIndex, pageSize, out totalRecord);
        //this.rpSanPhams.DataBind();
    }

    private void LoadSanPham()
    {
        EHTWebsite.Code.SanPham theSanPham = new EHTWebsite.Code.SanPham();
        theSanPham.DanhMucID = categoryID;
        theSanPham.NoiBat = false;
        theSanPham.TenSanPhamOther = "";
        theSanPham.TenSanPhamVN = "";

        //this.rpSanPhams.DataSource = SanPhamProvider.GetSanPhamsByFilter(theSanPham, pageIndex, pageSize, out totalRecord);
        //this.rpSanPhams.DataBind();
    }

    private void LoadTopLastestNews()
    {
        DanhMucTinTuc theDanhMucTinTuc = DanhMucTinTucProvider.GetDanhMucTinTucByDanhMucID(17);

        if (theDanhMucTinTuc == null)
        {
            Response.Redirect("~/trang-chu.aspx");
        }

        //load dữ liệu tin tức thiết kế website
        DataSet dsTinTucs = TinTucProvider.GetTinTucsByFillterForFrontEnd("", "", theDanhMucTinTuc.DanhMucTinTucID, pageIndex, pageSize, out totalRecord);
        //this.rpLastestNewsOfThietKe.DataSource = dsTinTucs;
        //this.rpLastestNewsOfThietKe.DataBind();

        //load dữ liệu tin tức tối ưu website
        theDanhMucTinTuc = DanhMucTinTucProvider.GetDanhMucTinTucByDanhMucID(22);
        dsTinTucs = TinTucProvider.GetTinTucsByFillterForBackEnd("", "", theDanhMucTinTuc.DanhMucTinTucID, pageIndex, pageSize, out totalRecord);
        //this.rpLastestNewsOfTuVan.DataSource = dsTinTucs;
        //this.rpLastestNewsOfTuVan.DataBind();
    }

    public String FormatStringForUrl(String input)
    {
        return HelpMethod.FormatStringForUrl(input);
    }

    public void LoadLanguage(CultureInfo ci)
    {
        //this.ltrGioiThieu_Title.Text = rm.GetString("ltrGioiThieu_Title", ci);
    }
}